package cn.tedu.imop.content.service.impl;

import cn.tedu.imop.common.annotation.RequiredOperationLog;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.content.dao.repository.ArticleRepository;
import cn.tedu.imop.content.entity.Article;
import cn.tedu.imop.content.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ArticleServiceImpl implements ArticleService {

    @Value("${logging.level.cn.tedu:debug}")
    private String logLevel;

    private final ArticleRepository articleRepository;

    public ArticleServiceImpl(ArticleRepository articleRepository) {
        this.articleRepository = articleRepository;
        System.out.println("logLevel:"+logLevel);
    }

    @Override
    public Boolean createArticle(Article article) {
        articleRepository.insertArticle(article);
        log.debug("article:{}",article);
        //将article对象在ES中保存一份
        //Article save = articleElasticSearchRepository.save(article);
        //log.debug("articleElasticSearchRepository.article:{}",save);

        return true;
    }
    @RequiredOperationLog(value="获取文章列表")
    @Override
    public PageData<Article> getArticleList(Article article) {
        System.out.println("logLevel:"+logLevel);
        PageData<Article> pageData=articleRepository.selectArticleList(article);
        //项目上线后，这个日志就不需要输出了
        log.debug("pageData:{}",pageData);
        return pageData;
    }
}
